package bod.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;

import bod.Progress;
import bod.engine.Engine;
import bod.gui.menu.Menu;

public class Screen {

	private static int		width;
	private static int		height;
	private static int		fps;
	private static boolean	showFps;
	private static Menu		menu;

	public static void initialize(int _width, int _height) {
		width = _width;
		height = _height;
		fps = 0;
		showFps = true;
		menu = null;
	}

	public static void draw(Graphics g) {
		if (Progress.isBusy()) {
			Progress.draw(g);
		} else {
			if (menu != null) {
				menu.draw(g);
			} else {
				Engine.draw(g);
			}
		}
		if (showFps) {
			g.setColor(Color.green);
			g.drawString("" + fps, 0, height);
		}
	}

	public static void keyPressed(int code) {
		if (code == KeyEvent.VK_F1) {
			showFps = !showFps;
		}
		if (!Progress.isBusy()) {
			if (menu != null) {
				menu.keyPressed(code);
			} else {
				Engine.keyPressed(code);
			}
		}
	}

	public static void keyReleased(int code) {
		if (!Progress.isBusy()) {
			if (menu != null) {
				menu.keyReleased(code);
			} else {
				Engine.keyReleased(code);
			}
		}
	}

	public static void mousePressed(int x, int y) {
		if (!Progress.isBusy()) {
			if (menu != null) {
				menu.mousePressed(x, y);
			} else {
				Engine.mousePressed(x, y);
			}
		}
	}

	public static void mouseReleased(int x, int y) {
		if (!Progress.isBusy()) {
			if (menu != null) {
				menu.mouseReleased(x, y);
			} else {
				Engine.mouseReleased(x, y);
			}
		}
	}

	public static void mouseMoved(int x, int y) {
		if (!Progress.isBusy()) {
			if (menu != null) {
				menu.mouseMoved(x, y);
			} else {
				Engine.mouseMoved(x, y);
			}
		}
	}

	public static void setFps(int _fps) {
		fps = _fps;
	}

	public static int getWidth() {
		return width;
	}

	public static int getHeight() {
		return height;
	}

}